<template>
  <div></div>
</template>

<script>
import { wxredirect_uri } from '@/config'

export default {
  data() {
    return {
    }
  },
  mounted() {
    //解决#号问题  http://www.iraetaforging.cn:6093/?code=Fs3hKYcW0qM0R2LcIAeP5H_frmEPh1EokjjgZ6M2g7g&state=STATE#/wxcode
    const url = window.location.href
    const code = url.match(/=(\S*)&state=STATE#/)
    if (code !== null) {
      // 如果能获得code，说明需要处理url并跳转，如果不能获得code，不用处理
      const replaceUrl = wxredirect_uri + '?code=' + code[1] + '&state=STATE'
      return window.location.replace(replaceUrl)
    } else {
      this.userLoginByCode()
    }
  },
  methods: {
    userLoginByCode(){
      let code = this.$route.query.code;
      this.$store.dispatch("user/wxLogin", code).then(()=>{
        this.$router.push({ path: "/" });
      })
    }
  }
}
</script>

<style scoped>

</style>
